package com.jeecms.wicool.dao.user.impl;


import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;
import com.jeecms.common.hibernate3.Finder;
import com.jeecms.common.hibernate3.HibernateBaseDao;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.user.ScoreTradeDao;
import com.jeecms.wicool.entity.user.ScoreTrade;

@Repository
public class ScoreTradeDaoImpl extends HibernateBaseDao<ScoreTrade, Integer>
		implements ScoreTradeDao {

	@Override
	protected Class<ScoreTrade> getEntityClass() {
		// TODO Auto-generated method stub
		return ScoreTrade.class;
	}
	@Override
	public Pagination getPage(Integer userId,String userName,int pageNo, int pageSize) {
			Finder f = Finder.create("select bean from ScoreTrade bean where 1=1 ");
			if(userId!=null){
				f.append(" and bean.user.id = :userId");
				f.setParam("userId",userId);
			}
			if (!StringUtils.isBlank(userName)){
				f.append(" and bean.user.name = :userName");
				f.setParam("userName",userName);
			}
			f.append(" order by bean.id desc");
			return find(f, pageNo, pageSize);
	}
	@Override
	public ScoreTrade findById(Integer id) {
		ScoreTrade  entity = get(id);
		return entity;
	}
	@Override
	public ScoreTrade save(ScoreTrade bean) {
		getSession().save(bean);
		return bean;
	}
	@Override
	public ScoreTrade deleteById(Integer id) {
		ScoreTrade entity = super.get(id);
		if (entity != null) {
			getSession().delete(entity);
		}
		return entity;
	}
	@Override
	public List<ScoreTrade> getListScoreTradeByUserId(Integer userId) {
		Finder f = Finder.create("select bean from ScoreTrade bean where bean.user.id = '"+ userId+"'");
		return find(f);
	}
}